package com.gupao.javavip.netty.push.client.processor;

import com.gupao.javavip.netty.push.api.MsgType;
import com.gupao.javavip.netty.push.api.PushMsg;
import com.gupao.javavip.netty.push.api.Request;
import com.gupao.javavip.netty.push.api.RequestCommand;
import lombok.extern.apachecommons.CommonsLog;

import java.util.UUID;

@CommonsLog
public class PushMsgClientService {
    private static final String NOTICE_TARGET = "-1";

    public Request buildPushMsgRequest() {
        return buildPushMsgRequestBase(MsgType.MSG);
    }

    public Request buildPushNoticeRequest() {
        return buildPushMsgRequestBase(MsgType.NOTICE);
    }

    private Request buildPushMsgRequestBase(MsgType msgType) {
        PushMsg msg = new PushMsg();
        msg.setId(UUID.randomUUID().toString());
        msg.setSendTime(System.currentTimeMillis());
        msg.setType(msgType.name());

        if (msgType.equals(MsgType.MSG)) {
            msg.setContent("一条推送消息！");
            msg.setPushTarget("USER-A");
        } else {
            msg.setContent("一则公告消息！");
            msg.setPushTarget(NOTICE_TARGET);
        }

        Request request = new Request();
        request.setCommand(RequestCommand.PUSH.name());
        request.setPushSource("Server");
        request.setMsg(msg);

        return request;
    }

    public Request buildReceiveRequest() {
        Request request = new Request();
        request.setCommand(RequestCommand.RECEIVE.name());
        request.setPushSource("USER-A");

        return request;
    }
}
